import { getToken, removeToken } from '@/utils/auth'
//import md5 from 'js-md5'

const state = {
  token: getToken(),
}

const mutations = {
  SET_TOKEN: (state, token) => {
    state.token = token
  },
}

const actions = {
  // user login
  /*login({ commit }, userInfo) {
    return new Promise((resolve, reject) => {
      const info = {
        username: userInfo.username,
        password: md5(userInfo.password),
        code: userInfo.code,
        sessionId: userInfo.sessionId
      }
      login(info).then(response => {
        commit('SET_TOKEN', response.data.token)
        setToken(response.data.token)
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  },


  // user logout
  logout({ commit }) {
    return new Promise((resolve) => {
      commit('SET_TOKEN', '')
      removeToken()
      resetRouter()
      resolve()
    })
  },*/

  // remove token
  resetToken({ commit }) {
    return new Promise(resolve => {
      commit('SET_TOKEN', '')
      removeToken()
      resolve()
    })
  },

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
